/*
 * Classe Database
 *      Provê conexão ao banco de dados
 * Equipe:
 *      Menandro Dias
 *      Pedro Alípio
 *      Sidney dos Santos
 *      Ubirajara Gabriela
 *
 */

package tcpserver.model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author menandro.neto
 */
public class Database {
    private Connection connection;
    private String urlDatabase;
    private String urlDriver;
    private String dbUserName;
    private String dbPassword;

    public Database(){
        urlDatabase = "jdbc:jtds:sqlserver://localhost/DomPedroRedesI";
        urlDriver   = "net.sourceforge.jtds.jdbc.Driver";
        dbUserName  = "dompedro";
        dbPassword  = "sysrq";
    }

    public void connect(){
        try {
            Class.forName(urlDriver);
            connection = DriverManager.getConnection(urlDatabase, dbUserName, dbPassword);
		} catch (ClassNotFoundException ex) {
            ex.printStackTrace();
		} catch (SQLException ex) {
            ex.printStackTrace();
		}
    }

    public void execSQL(String sqlString){
        try {
            Statement stm = connection.createStatement();
            stm.executeUpdate(sqlString);
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void disConnect(){
        try {
            connection.close();
		} catch (SQLException ex) {
            ex.printStackTrace();
		}
    }


}
